package com.example.transit.contentprovider;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;


public class DbHelper extends SQLiteOpenHelper {

    private static final String DATABASE_NAME = "transit.db";

    private static final int VERSION_CURRENT = 1;


    //所以站点信息表
    public static final String TABLE_ALLSTATION = "tb_allstation";
    public static final String COLUME_ALLSTA_ID = "id";
    public static final String COLUME_ALLSTA_LINE = "sta_line";
    public static final String COLUME_ALLSTA_DIRECT = "direct";
    public static final String COLUME_ALLSTA_STA_NAME = "sta_name";
    public static final String COLUME_ALLSTA_STA_ORDER = "sta_order";
    public static final String COLUME_ALLSTA_GPS_X = "gps_x";
    public static final String COLUME_ALLSTA_GPS_Y = "gps_y";

    //历史记录表
    //所以站点信息表
    public static final String TABLE_HISTORY = "tb_history";
    public static final String COLUME_HISTORY_ID = "id";
    public static final String COLUME_HISTORY_LINE = "sta_line";
    public static final String COLUME_HISTORY_DIRECT = "direct";
    public static final String COLUME_HISTORY_NAME = "sta_name";


    private static final String SQL_CREATE_TABLE_TABLE_ALLSTATION=
            "CREATE TABLE IF NOT EXISTS " + TABLE_ALLSTATION + " (" +
                    COLUME_ALLSTA_ID + " INT," +
                    COLUME_ALLSTA_LINE + " VARCHAR," +
                    COLUME_ALLSTA_STA_NAME + " VARCHAR, " +
                    COLUME_ALLSTA_STA_ORDER + " VARCHAR," +
                    COLUME_ALLSTA_DIRECT + " BOOLEAN," +
                    COLUME_ALLSTA_GPS_X + " VARCHAR, " +
                    COLUME_ALLSTA_GPS_Y + " VARCHAR)";
    public static final String SQL_DELETE_TABLE_ALLSTATION_DATA=
            "truncate TABLE IF EXISTS " + TABLE_ALLSTATION ;

    //历史记录
    private static final String SQL_CREATE_TABLE_HISTORY=
            "CREATE TABLE IF NOT EXISTS " + TABLE_HISTORY + " (" +
                    COLUME_HISTORY_ID + " INT," +
                    COLUME_HISTORY_LINE + " VARCHAR," +
                    COLUME_HISTORY_NAME + " VARCHAR, " +
                    COLUME_HISTORY_DIRECT + " BOOLEAN )";


    private static final String TAG = "DbHelper";

    public DbHelper(Context context) {
        super(context, DATABASE_NAME, null, VERSION_CURRENT);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        Log.d(TAG, "create database neeed tables.");

        db.execSQL(SQL_CREATE_TABLE_TABLE_ALLSTATION);
        db.execSQL(SQL_CREATE_TABLE_HISTORY );
    }


    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "upgrade database ");
        Log.d(TAG, "oldVersion " + oldVersion + ",newVersion " + newVersion);

        switch (oldVersion) {
            case 1:
            default:
                break;

        }
    }

    @Override
    public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        Log.d(TAG, "down database ");
        Log.d(TAG, "oldVersion " + oldVersion + ",newVersion " + newVersion);

        switch (newVersion) {
            case 1:
            default:
                break;
        }

    }

}